import 'package:flutter/material.dart';
import '../models/airplane_model.dart';
import '../models/control_mode.dart';
import 'control_screens/manual_control_screen.dart';
import 'control_screens/gravity_control_screen.dart';
import 'control_screens/path_control_screen.dart';
import 'control_screens/voice_control_screen.dart';
import 'programming_screen.dart';

class ControlModeSelectionScreen extends StatelessWidget {
  final AirplaneModel model;

  const ControlModeSelectionScreen({super.key, required this.model});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('选择控制模式')),
      body: Column(
        children: [
          // Container(
          //   padding: const EdgeInsets.all(16.0),
          //   color: Theme.of(context).colorScheme.surfaceVariant,
          //   child: Row(
          //     children: [
          //       Icon(
          //         Icons.airplanemode_active,
          //         size: 48,
          //         color: Theme.of(context).colorScheme.primary,
          //       ),
          //       const SizedBox(width: 16),
          //       Expanded(
          //         child: Column(
          //           crossAxisAlignment: CrossAxisAlignment.start,
          //           children: [
          //             Text(
          //               model.name,
          //               style: Theme.of(context).textTheme.titleLarge,
          //             ),
          //             const SizedBox(height: 4),
          //             Text(
          //               model.category,
          //               style: Theme.of(context).textTheme.bodyMedium,
          //             ),
          //           ],
          //         ),
          //       ),
          //     ],
          //   ),
          // ),
          // Padding(
          //   padding: const EdgeInsets.all(16.0),
          //   child: Text(
          //     '请选择控制模式',
          //     style: Theme.of(context).textTheme.headlineSmall,
          //   ),
          // ),
          Expanded(
            child: ListView(
              padding: const EdgeInsets.all(16.0),
              children:
                  ControlMode.values.map((mode) {
                    return _buildControlModeCard(context, mode);
                  }).toList(),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildControlModeCard(BuildContext context, ControlMode mode) {
    return Card(
      margin: const EdgeInsets.only(bottom: 16.0),
      child: InkWell(
        onTap: () {
          _navigateToControlScreen(context, mode);
        },
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Row(
            children: [
              Container(
                width: 60,
                height: 60,
                decoration: BoxDecoration(
                  color: Theme.of(context).colorScheme.primaryContainer,
                  borderRadius: BorderRadius.circular(12),
                ),
                child: Icon(
                  mode.icon,
                  size: 32,
                  color: Theme.of(context).colorScheme.onPrimaryContainer,
                ),
              ),
              const SizedBox(width: 16),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      mode.name,
                      style: Theme.of(context).textTheme.titleMedium?.copyWith(
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    const SizedBox(height: 4),
                    Text(
                      mode.description,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ],
                ),
              ),
              Icon(
                Icons.arrow_forward_ios,
                color: Theme.of(context).colorScheme.primary,
              ),
            ],
          ),
        ),
      ),
    );
  }

  void _navigateToControlScreen(BuildContext context, ControlMode mode) {
    Widget screen;

    switch (mode) {
      case ControlMode.manual:
        screen = ManualControlScreen(model: model);
        break;
      case ControlMode.gravity:
        screen = GravityControlScreen(model: model);
        break;
      case ControlMode.path:
        screen = PathControlScreen(model: model);
        break;
      case ControlMode.voice:
        screen = VoiceControlScreen(model: model);
        break;
      case ControlMode.programming:
        screen = ProgrammingScreen(airplaneModel: model);
        break;
    }

    Navigator.push(context, MaterialPageRoute(builder: (context) => screen));
  }
}
